<?php
class App_Activity_Build
{
    public function __construct ($activityId = NULL)
    {
        $this->_activityId = $activityId;
    }

    // 创建基本活动
    // STEP 1
    public function createByBasic ($uid, $country,$cityId, $city, $location,
        $srv70s, $srv80s, $srv90s, $srv00s, 
        $minPersons, $maxPersons, $lat, $lng)
    {
        $row = array(

            'city'       => $city,
            'cityId'     => $cityId,
            'country'    => $country,
            'location'   => $location,
        	'lat'        => $lat,
        	'lng'        => $lng,

            'uid'        => $uid,
            'created'    => DB::expr('unix_timestamp(now())'),
            'changed'    => DB::expr('unix_timestamp(now())'),
            'status'     => 'INVALID',

            'support70s' => (int) $srv70s,
            'support80s' => (int) $srv80s,
            'support90s' => (int) $srv90s,
            'support00s' => (int) $srv00s,

            'serviceMinPersons' => (int) $minPersons,
            'serviceMaxPersons' => (int) $maxPersons,
        );

        list($insert_id, $rows) = DB::insert('mod_activity')
            ->columns (array_keys($row))
            ->values(array_values($row))
            ->execute();

        return $insert_id;
    }

    public function updateBasic ($activityId, $uid, $country, $city,$cityId, $location,
        $srv70s, $srv80s, $srv90s, $srv00s, 
        $minPersons, $maxPersons, $lat, $lng)
    {
        $row = array(

            'city'       => $city,
            'cityId'     => $cityId,
            'country'    => $country,
            'location'   => $location,
            'lat'        => $lat,
        	'lng'        => $lng,

            'changed'    => DB::expr('unix_timestamp(now())'),

            'support70s' => (int) $srv70s,
            'support80s' => (int) $srv80s,
            'support90s' => (int) $srv90s,
            'support00s' => (int) $srv00s,

            'serviceMinPersons' => (int) $minPersons,
            'serviceMaxPersons' => (int) $maxPersons,
        );

        $rows = DB::update('mod_activity')
            ->set($row)
            ->where('id', '=', $activityId)
            ->execute();

        return $rows > 0;
 
    }



    public function updateDays ($activityId, $name, $summary, $todolist, $hours, $thumb, $banner, $images)
    {
        $row = array(
            'name'    => $name,
            'summary' => $summary,
            'todolist'=> $todolist,
            'hours'   => $hours,
            'changed' => DB::expr('unix_timestamp(now())'),
        );

        if (! empty($thumb))
            $row['thumb'] = $thumb;

        if (! empty($banner))
            $row['bannerUrl'] = $banner;

        // images
        if (! empty($images))
        {            
            $imagesStr = implode('|', $images);

            if (! empty($imagesStr))
                $row['images'] = $imagesStr;
        }

        $rows = DB::update('mod_activity')
            ->set($row)
            ->where('id', '=', $activityId)
            ->execute();

        return $rows > 0;
    }

    public function updateTimes ($activityId, $startDay, $stopDay, $freeTimeDays)
    {
        $row = array(
            'startDay'=> $startDay,
            'stopDay' => $stopDay,
            'freeTimeDays' => $freeTimeDays,
            'changed' => DB::expr('unix_timestamp(now())'),
        );

        $rows = DB::update('mod_activity')
            ->set($row)
            ->where('id', '=', $activityId)
            ->execute();

        return $rows > 0;
    }

    public function updatePrice($activityId, $priceService, $descService)
    {
        $row = array(
            'priceService' => (int) ($priceService * 100),
            'descService'   => $descService,
            'priceTotal' => (int) ($priceService * 100),
            'changed' => DB::expr('unix_timestamp(now())'),
        );

        $rows = DB::update('mod_activity')
            ->set($row)
            ->where('id', '=', $activityId)
            ->execute();

        return $rows > 0;
    }

    public function updateBank($activityId, $accountType, $accountName, $accountUserName)
    {
        $row = array(
            'accountType'     => $accountType,
            'accountName'     => $accountName,
            'accountUserName' => $accountUserName,

            'status'  => 'VALID',
            'changed' => DB::expr('unix_timestamp(now())'),
        );

        $rows = DB::update('mod_activity')
            ->set($row)
            ->where('id', '=', $activityId)
            ->execute();

        return $rows > 0;
    }

}
